/*
 * @(#) EncryptorTestScheduler
 * 版权声明 厦门畅享信息技术有限公司, 版权所有 违者必究
 *
 * <br> Copyright:  Copyright (c) 2024
 * <br> Company:厦门畅享信息技术有限公司
 * <br> @author Administrator
 * <br> 2024-01-30 09:57:16
 */

package com.lost.octopus.es.processor.scheduler;

import org.apache.commons.lang3.StringUtils;;
import com.sunsharing.share.common.base.DateUtil;
import com.sunsharing.share.job.context.XxlJobContext;
import com.lost.octopus.es.processor.dao.mapper.mybatis.ResidentMapper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalTime;

import static com.sunsharing.share.common.base.DateUtil.TIME_FORMAT;

/**
 * 验证加密机性能的调度
 * @author zhangbh
 * @date 2024/1/30 9:57
 */
@Log4j2
@Component
public class EncryptorTestScheduler {

    @Resource
    private ResidentMapper residentMapper;


    @XxlJob("EncryptorTestScheduler")
    public void execute() {
        String jobParam = XxlJobContext.getXxlJobContext().getJobParam();

        Integer count = StringUtils.isBlank(jobParam) ? 1000 : Integer.parseInt(jobParam);
        LocalTime now = LocalTime.now();
        residentMapper.select1000Test(count);
        LocalTime now1 = LocalTime.now();
        log.info("加解密{}个字段，{}~{} 耗时{}毫秒,{}秒",
                count,
                DateUtil.toString(now, TIME_FORMAT),
                DateUtil.toString(now1,TIME_FORMAT),
                Duration.between(now, now1).toMillis(),
                Duration.between(now, now1).toMillis() / 1000
        );
    }
}
